import threading
import queue
import random
import time

q = queue.Queue()

item = 0

def produce():
    global item
    while True:
        time.sleep(1)
        item = random.randint(1,10)
        q.put(item)
        print('producer {}th goods append to q.'.format(item))
        time.sleep(1)

def consumer():
    while True:
        item = q.get()
        print(threading.currentThread().getName()+
              'consumer get {}th goods from q.'.format(item))
        q.task_done()

if __name__ == "__main__":
    threads_consumer = []
    for i in range(3):
        t = threading.Thread(target=consumer)
        t.start()
        threads_consumer.append(t)

    thread_producer = threading.Thread(target=produce)
    thread_producer.start()
    q.join()
    for t in threads_consumer:
        t.join()
    thread_producer.join()